﻿package com.athena.ui 
{
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	
	public class BasicButton extends Sprite
	{
		private var _label:String;
		private var allButtons:Array;
		
		public function BasicButton()
		{
			buttonMode = true;
			label_txt.mouseEnabled = false;
			allButtons = [normal_mc,down_mc,over_mc];
			hideAllExcept(normal_mc);
			//draw(width,height);
			addEventListener(MouseEvent.MOUSE_UP, handleMouse);
			addEventListener(MouseEvent.MOUSE_DOWN, handleMouse);
			addEventListener(MouseEvent.ROLL_OVER, handleMouse);
			addEventListener(MouseEvent.ROLL_OUT, handleMouse);
		}
		
		public function draw(w:Number, h:Number):void
		{
			scaleX = scaleY = 1;
			
			for(var i:uint = 0; i < allButtons.length; i++)
			{
				var btn:MovieClip = allButtons[i];	
				btn.main_mc.width = w// - btn.right_mc.width * 2;
				btn.main_mc.x = btn.left_mc.x + btn.left_mc.width;
				btn.right_mc.x = btn.main_mc.x + btn.main_mc.width;
			}
		}
		
		private function handleMouse(event:MouseEvent):void
		{
			switch(event.type)
			{
				case MouseEvent.ROLL_OVER :
				hideAllExcept(over_mc);
				break;
				case MouseEvent.ROLL_OUT :
				hideAllExcept(normal_mc);
				break;
				case MouseEvent.MOUSE_DOWN :
				hideAllExcept(down_mc);
				break;
				case MouseEvent.MOUSE_UP :
				hideAllExcept(over_mc);
				break;
				default :
				break;
			}
		}
		
		private function hideAllExcept(except:MovieClip):void
		{
			for(var i:uint = 0; i < allButtons.length; i++)
			{
				allButtons[i].alpha = (allButtons[i] == except) ? 1 : 0;	
			}
		}
		
		public function set label(l:String):void
		{
			_label = l;
			label_txt.text = _label;
		}
		
		public function get label():String
		{
			return _label;
		}
	}
}